package com.yc.navy.springmvc.interceptor;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;

import com.yc.navy.springmvc.util.ConstantIfo;



public class FrontCheckInterceptor implements HandlerInterceptor{
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		if(request.getSession().getAttribute(ConstantIfo.CURRENTLOGINMEMBER) == null) {
			response.setContentType("text/html;charset=utf-8");
			PrintWriter out = response.getWriter();
			out.print("<script>alert('请先登录...');location.href='" + request.getContextPath() + "/login.html'</script>");
			out.flush();
			return false;
		}
		return true;
	}
}
